﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Text;

namespace peonwar
{
    public enum Language
    {
        French,
        English,
    }

    static class GameData
    {
        // ---PROPERTIES---
        // Classe pour stocker les textes et les polices du jeu
        static public SpriteFont Font_Simple;
        static public SpriteFont Font_Menu;
        static public SpriteFont Font_Pause;
        static public SpriteFont Font_Big;
        static public SpriteFont Font_Profil;
        static public SpriteFont Font_Simple2;
        static public SpriteFont Font_Quake;
        static public SpriteFont Font_Begin;
        static public SpriteFont Font_Timer;
        static public SpriteFont Font_Cursor_Little;
        static public SpriteFont Font_Cursor_Medium;
        static public SpriteFont Font_Cursor_Big;
        static public SpriteFont Font_Achiev;
        static public SpriteFont Font_Achiev2;
        static public SpriteFont Font_Arial;



        static public List<string> GameString = new List<String>();
        static public Language CurrentLanguage;


        // ---METHODES---
        static public void LoadContent(ContentManager content)
        {
            // Charge les polices
            Font_Simple = content.Load<SpriteFont>("Fonts/Font_Simple");
            Font_Menu = content.Load<SpriteFont>("Fonts/Font_Menu");
            Font_Pause = content.Load<SpriteFont>("Fonts/Font_Pause");
            Font_Big = content.Load<SpriteFont>("Fonts/Font_Big");
            Font_Profil = content.Load<SpriteFont>("Fonts/Font_Profil");
            Font_Simple2 = content.Load<SpriteFont>("Fonts/Font_Simple_v2");
            Font_Quake = content.Load<SpriteFont>("Fonts/Font_Quake");
            Font_Begin = content.Load<SpriteFont>("Fonts/Font_Begin");
            Font_Timer = content.Load<SpriteFont>("Fonts/Font_Timer");
            Font_Cursor_Little = content.Load<SpriteFont>("Fonts/Font_Cursor_Little");
            Font_Cursor_Medium = content.Load<SpriteFont>("Fonts/Font_Cursor_Medium");
            Font_Cursor_Big = content.Load<SpriteFont>("Fonts/Font_Cursor_Big");
            Font_Achiev = content.Load<SpriteFont>("Fonts/Font_Achie");
            Font_Achiev2 = content.Load<SpriteFont>("Fonts/Font_Achie2");
            Font_Arial = content.Load<SpriteFont>("Fonts/Arial");
        }

        // Update la liste de string du jeu avec le ficheir language adapte
        static public void UpdateLanguage()
        {
            GameString.Clear();
            using (StreamReader reader = new StreamReader("Content/Languages/" + GetLanguagePath(CurrentLanguage), Encoding.Default))
            {
                string line;
                string stock;// YA QUOI MAINTENANT C# ON OUVRE PLUS SA PUTAIN DE GUEULE HEIN§§§ GROS PD DE MERDE
                while ((line = reader.ReadLine()) != null)
                {
                    string retour = "";
                    stock = line.Substring(5, line.Length - 5);
                    for (int i = 0; i < stock.Length - 1; i++)
                    {
                        if (stock[i] == '\\' && stock[i + 1] == 'n')
                        {
                            retour += "\n";
                            i++;
                        }
                        else
                            retour += stock[i];
                    } 
                    retour += stock[stock.Length - 1];
                    GameString.Add(retour);
                }
            }
        }

        // Passe du type language au chemin du fichier language correspondant
        static string GetLanguagePath(Language language)
        {
            switch (language)
            {
                case Language.French:
                    return "French.pwl";
                case Language.English:
                    return "English.pwl";
                default: 
                     return "English.pwl";
            }
        }

        static public string GetLanguage()
        {
            switch (CurrentLanguage)
            {
                case Language.English:
                    return GameData.GameString[28];
                case Language.French:
                    return GameData.GameString[29];
                default:
                    return "";
            }
        }
    }
}
